/*
  Copyright (c) 2009 by kRaw1er
  This file is part of M8J project
*/
#include "CSingleLineEdit.h"
#include "CChatWnd.h"

CSingleLineEdit::CSingleLineEdit(CChatWnd * parent)
:	m_Parent(parent)
{
}

CSingleLineEdit::~CSingleLineEdit(void)
{
}

void CSingleLineEdit::OnFocused(UiWin * pWinPrev)
{
	UiSingleLineEdit::OnFocused(pWinPrev);

	if (m_Parent)
	{
		m_Parent->m_Toolbar.SetButtonText(0, STR_SEND.c_str());
		m_Parent->m_Toolbar.Invalidate();
		m_Parent->m_Toolbar.Update();
		RECT rc = MzGetVisibleDesktopRect();
		m_Parent->ResizeChatList(rc, true);
	}
}

void CSingleLineEdit::OnLostFocus(UiWin * pWinNext)
{
	UiSingleLineEdit::OnLostFocus(pWinNext);

	if (m_Parent)
	{
		//m_Parent->m_Toolbar.SetButtonText(0, STR_BACK.c_str());
		m_Parent->m_Toolbar.Invalidate();
		m_Parent->m_Toolbar.Update();
		RECT rc = MzGetWorkArea();
		m_Parent->ResizeChatList(rc, false);
		MzCloseSip();
	}
}

int CSingleLineEdit::OnChar(TCHAR chCharCode, LPARAM lKeyData)
{
	int ret = UiSingleLineEdit::OnChar(chCharCode, lKeyData);

	if (chCharCode == 13) // enter key
	{
		if (m_Parent)
			m_Parent->OnSendMessage();
		SetText(L"");
		Invalidate();
	}

	return ret;
}
